import sys
from typing import List


class Solution:
    def gameResult(self, cards_1, cards_2):
        table = []
        count_1, count_2 = 0, 0
        for i in range(len(cards_1)):
            table.append(cards_1[i])
            point_1, table = self.getPoint(table)
            count_1 += point_1

            table.append(cards_2[i])
            point_2, table = self.getPoint(table)
            count_2 += point_2
        for j in range(len(table)):
            if table[j] % 2 == 1:
                count_1 += 1
            else:
                count_2 += 1
        return count_1, count_2

    def getPoint(self, table: List):
        if table[-1] in table[:-1]:
            idx = table.index(table[-1])
            point = len(table[idx:])
            return point, table[:idx]
        else:
            return 0, table


class Solution1:
    def gameResult(self, cards_1: List, cards_2: List):
        table = []
        count_1, count_2 = 0, 0
        while cards_1 and cards_2:
            table.append(cards_1.pop(0))
            point_1, table = self.getPoint(table)
            count_1 += point_1
            while point_1 > 0 and cards_1:
                table.append(cards_1.pop(0))
                point_1, table = self.getPoint(table)
                count_1 += point_1

            table.append(cards_2.pop(0))
            point_2, table = self.getPoint(table)
            count_2 += point_2
            while point_2 > 0 and cards_2:
                table.append(cards_2.pop(0))
                point_2, table = self.getPoint(table)
                count_2 += point_2
        res = cards_1 if cards_1 else cards_2
        table.extend(res)  # error
        for j in range(len(table)):
            if table[j] % 2 == 1:
                count_1 += 1
            else:
                count_2 += 1
        return count_1, count_2

    def getPoint(self, table: List):
        if table[-1] in table[:-1]:
            idx = table.index(table[-1])
            point = len(table[idx:])
            return point, table[:idx]
        else:
            return 0, table


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    p1 = sys.stdin.readline().strip()
    p2 = sys.stdin.readline().strip()
    p1 = list(map(int, p1.split(' ')))
    p2 = list(map(int, p2.split(' ')))

    s = Solution1()
    a, b = s.gameResult(p1, p2)
    print(str(a), str(b))
